﻿$(document).ready(function () {
    //    $("#drcngaynhan").datepicker({ dateFormat: 'dd/mm/yy' });
    //    $("#drcbirthdate").datepicker({ dateFormat: 'dd/mm/yy' });
    //    $("#drcngaycap").datepicker({ dateFormat: 'dd/mm/yy' });
    //    $("#txt_ngayvuan").datepicker({ dateFormat: 'dd/mm/yy' });
    //    $("#txt_ngayxetxu").datepicker({ dateFormat: 'dd/mm/yy' });
    //    $("#txtFieldFromDateRecorded").datepicker({ dateFormat: 'dd/mm/yy' });
    //    $("#txtFieldToDateRecorded").datepicker({ dateFormat: 'dd/mm/yy' });
    //    $("#txtFieldFromCaseDate").datepicker({ dateFormat: 'dd/mm/yy' });
    //    $("#txtFieldToCaseDate").datepicker({ dateFormat: 'dd/mm/yy' });
});


function fireParentForm(LevelLocationType, WebpartId, PermissionCode) {

}

function SwitchLevelType(LevelLocationType, WebpartId, PermissionCode) {
    if (LevelLocationType == "0") {
        $("#_locationSelect").html("");
        return;
    }
    var filter = Portal.SODC.IDIS.Locations.ServerSideRenderFilter(LevelLocationType, WebpartId, PermissionCode).value;
    if (filter.indexOf("NONE") != -1) {
        $("#_filterpanel").html("Không có dữ liệu lọc theo cấp trên.");
        $("#_locationSelect").html(Portal.SODC.IDIS.Locations.LocationBuilder(LevelLocationType, WebpartId, PermissionCode).value);
    }
    else {
        $("#_filterpanel").html(filter);
    }
}


var SearchType = 1;
// for AdvSearch
function ShowAdvSearch() {
    em1 = document.getElementById("divSimpleSearch");
    em = document.getElementById("advSearch");
    if (em.style.display == "block") {
        em.style.display = "none";
        em1.style.display = "block";
        SearchType = 1;
    }
    else {
        em.style.display = "block";
        em1.style.display = "none";
        SearchType = 2;
    }

}

// SaveTempCurrency

function ClientSaveItem(Type, ControlName, WpId) {
    var CurrNo;
    var em;
    var CurrUnit;
    var CurrName;
    var CurrKeyCode;
    CurrNo = document.getElementById("txt_" + ControlName).value;
    em = document.getElementById("sl_" + ControlName);
    CurrUnit = em.options[em.options.selectedIndex].value;
    CurrKeyCode = CurrUnit.split('|');
    CurrName = em.options[em.options.selectedIndex].text;
    if (CurrNo == '' || CurrKeyCode[0] == '0' || CurrNo == '0') {
        alert("Bạn phải nhập số lượng và đơn vị!");
        return;
    } else {
        if (IsNumeric(CurrNo)) {
            if (WpId == '0') {
                var Ret = Portal.SODC.IDIS.AddNewCrime.ClientAddToTempList(CurrNo, CurrKeyCode[0], CurrName, Type, ControlName, CurrKeyCode[1]).value;
            } else {
                var Ret = Portal.SODC.IDIS.FCrimeEditWP.ClientAddToTempList(CurrNo, CurrKeyCode[0], CurrName, Type, ControlName, CurrKeyCode[1]).value;
            }
        } else {
            alert("Yêu cầu nhập số!");
            return;
        }
    }
    document.getElementById("div_" + ControlName).innerHTML = Ret;
}


function ClientRemoveItem(CurrId, Type, ControlDiv, WpId) {
    if (WpId == '0') {
        var Ret = Portal.SODC.IDIS.AddNewCrime.ClientRemoveItem(CurrId, Type, ControlDiv).value;
    } else {
        var Ret = Portal.SODC.IDIS.FCrimeEditWP.ClientRemoveItem(CurrId, Type, ControlDiv).value;
    }
    document.getElementById("div_" + ControlDiv).innerHTML = Ret;

}


function ClientAddUnit(Type, isTextbox) {

    QuickAddUnitEnvidence(Type, isTextbox); // Hàm để hiển thị ra bảng dữ liệu về tang chung vat chung

}

function ClientAddGroup(Type) {
    QuickAddUnitEnvidence(Type);
}

function ServerSideSaveUnit(isTexbox) {

    var UnitValue = document.getElementById("txt_unitvalue").value;
    var UnitName = document.getElementById("txt_unitname").value;
    var fk_TypeEnvidence = $("#_Envidencetype").val();
    if (UnitValue == '' || UnitName == '') {
        alert("Yêu cầu nhập tên và viết tắt của đơn vị!");
    } else {
        var Ret = Portal.SODC.IDIS.Ultility.ServerSideAddUnit(UnitName, UnitValue, fk_TypeEnvidence).value;
        if (Ret.indexOf("ERROR") != -1) {
            alert(Ret.replace("ERROR: ", ""));
            return;
        } else {
            alert("Thêm đơn vị thành công!!!");
            if (isTexbox.indexOf("true") != -1) {
                var Ret1 = Portal.SODC.IDIS.AddNewCrime.ClientRenderEnvidenceCaseNarcotics().value;
                document.getElementById("divRenderTextbox").innerHTML = Ret1;
            } else {
                var Ret1 = Portal.SODC.IDIS.AddNewCrime.ClientRenderEnvidenceCaseAsset().value;
                document.getElementById("divRenderSelectBox").innerHTML = Ret1;
            }
        }
    }
}

function ServerSideSaveGroup() {
    var GroupName = document.getElementById("txt_GroupName").value;
    var GroupDesc = document.getElementById("txt_GroupDesc").value;
    var parentId = $("#_Envidencetype").val();
    if (GroupName == '' || GroupDesc == '') {
        alert("Yêu cầu nhập tên và mô tả nhóm!");
    } else {
        var Ret = Portal.SODC.IDIS.Ultility.ServerSideAddGroup(GroupName, GroupDesc, parentId).value;
        if (Ret.indexOf("ERROR") != -1) {
            alert(Ret);
            return;
        } else {
            alert("Thêm nhóm thành công!!!");
        }
    }

}

function addOption(txt, val, ControlName) {
    var em = document.getElementById("sl_" + ControlName);
    em.options[em.options.length] = new Option(txt, val);
}

function addTextbox(name, txt, val, ControlName) {
    var em = document.getElementById(ControlName);
    em.innerHTML = "<td>" + name + "</td><td><input type = text id = \"" + val + "\" ></td>";
}


function ClientViewCaseDetail(CaseId) {

    Url = Portal.SODC.IDIS.FCrimeDetailWP.GetShowViewForm(CaseId).value;
    if (Url.indexOf("ERROR") != -1) {
        alert(Url);
        return;
    } else {
        window.open(Url, "_blank");
    }
}

// Export data

function ClientSideExportDataCrime() {
//    var LocationId = $("#_locationsel").val();
//    if (typeof (LocationId) == 'undefined' || LocationId == null) {
//        alert("Bạn phải chọn cấp - địa phương để xuất dữ liệu !");
//        return;
//    }
//    Ret = Portal.SODC.IDIS.FCrimeWP.ServerExportData(LocationId).value;
//    document.getElementById("divProcessingSearchResult").innerHTML = "Hệ thống đang xử lý";
//    if (Ret.indexOf("ERROR") != -1) {
//        alert(Ret);
//        document.getElementById("divProcessingSearchResult").innerHTML = "";
//        return;
//    } else {
//        document.getElementById("divProcessingSearchResult").innerHTML = "";
//        window.open(Ret, "_blank");
    //    }

    var ltype = $("#selectlevel").val();
    if (ltype == "0") {
        alert("Chưa xác định địa phương!");
        return;
    }
    var LocationId = $("#_locationsel").val();
    ps = null;
    rValue = null;
    var toidanh = null;
    var result = document.getElementById("ContentSearchResult");
    if (SearchType == '1') {
        var Keyword = document.getElementById("txtSearchKeyword").value;
        var HomeTown = document.getElementById("txt_hometown").value;
        var Indent = document.getElementById("txt_indent").value;
        var Case = document.getElementById("txt_case").value;
        var Age = document.getElementById("select_age").options[document.getElementById("select_age").selectedIndex].value;
        result.style.display = "block";
        document.getElementById("divProcessingSearchResult").innerHTML = Portal.SODC.IDIS.FCrimeWP.GetProcessingText().value;
        Ret = Portal.SODC.IDIS.FCrimeWP.ServerExportData(LocationId, Keyword, HomeTown, Age, Indent, Case,rValue, toidanh).value;
    } else {
        rValue = ClientDoSearch();
        toidanh = GetItemCrimeSubject();
        document.getElementById("divProcessingSearchResult").innerHTML = Portal.SODC.IDIS.FCrimeWP.GetProcessingText().value;
        Ret = Portal.SODC.IDIS.FCrimeWP.ServerExportData(LocationId, Keyword, HomeTown, Age, Indent, Case, rValue, toidanh).value;
    }
    if (Ret.indexOf("ERROR") != -1) {
        document.getElementById("divProcessingSearchResult").innerHTML = "";
        alert(Ret.replace("ERROR: ", ""));
        result.innerHTML = "";
        return;
    }
    document.getElementById("divProcessingSearchResult").innerHTML = "";
    window.open(Ret, "_blank");
}



function ClientDoSimpleSearchCrime(Type) {
    var ltype = $("#selectlevel").val();
    if (ltype == "0") {
        alert("Chưa xác định địa phương!");
        return;
    }
    var LocationId = $("#_locationsel").val();
    ps = null;
    rValue = null;
    var toidanh = null;
    var result = document.getElementById("ContentSearchResult");
    if (Type == '1') {
        var Keyword = document.getElementById("txtSearchKeyword").value;
        var HomeTown = document.getElementById("txt_hometown").value;
        var Indent = document.getElementById("txt_indent").value;
        var Case = document.getElementById("txt_case").value;
        var Age = document.getElementById("select_age").options[document.getElementById("select_age").selectedIndex].value;
        result.style.display = "block";
        document.getElementById("divProcessingSearchResult").innerHTML = Portal.SODC.IDIS.FCrimeWP.GetProcessingText().value;
        Ret = Portal.SODC.IDIS.FCrimeWP.GetResult("app", LocationId, Keyword, HomeTown, Age, Indent, Case, 0, "JumpPageSearchResult", ps, rValue, toidanh).value;
    } else {
        rValue = ClientDoSearch();
        toidanh = GetItemCrimeSubject();
        document.getElementById("divProcessingSearchResult").innerHTML = Portal.SODC.IDIS.FCrimeWP.GetProcessingText().value;
        Ret = Portal.SODC.IDIS.FCrimeWP.GetResult("app", LocationId, Keyword, HomeTown, Age, Indent, Case, 0, "JumpPageSearchResult", ps, rValue, toidanh).value;
    }
    if (Ret.indexOf("ERROR") != -1) {
        document.getElementById("divProcessingSearchResult").innerHTML = "";
        alert(Ret.replace("ERROR: ", ""));
        result.innerHTML = "";
        return;
    }
    document.getElementById("divProcessingSearchResult").innerHTML = "";
    result.innerHTML = Ret;
}





function ClientSideExportDataCase() {

    var LocationId = $("#_locationsel").val();
    if (typeof (LocationId) == 'undefined' || LocationId == null) {
        alert("Bạn phải chọn cấp - địa phương để xuất dữ liệu !");
        return;
    }
    Ret = Portal.SODC.IDIS.ListCrimeCase.ServerExportDataCase(LocationId).value;
    document.getElementById("divProcessingSearchResult").innerHTML = "Hệ thống đang xử lý";
    if (Ret.indexOf("ERROR") != -1) {
        alert(Ret);
        document.getElementById("divProcessingSearchResult").innerHTML = "";
        return;
    } else {
        document.getElementById("divProcessingSearchResult").innerHTML = "";
        window.open(Ret, "_blank");
    }
}

function ClientStatus() {
    alert("Chuyên mục này đang xây dựng!");
    return;
}

// For QuckSearch
function UsingQuickSearch() {
    cmt = document.getElementById("drcCMT").value; // Custom: lấy dữ liệu về số cmnd ở đây.
    document.getElementById("divProcessing").innerHTML = "Hệ thống đang xử lý";
    QuickFindPerson(cmt); // Hàm để hiển thị ra bảng dữ liệu về người nghiện đã tìm thấy
    document.getElementById("divProcessing").innerHTML = "";
}

function FoundPerson(PersonId, PersonType) {
    // Custom: điền dữ liệu khi đã lấy được id của person
    var url = Portal.SODC.IDIS.AddNewCrime.GetShowUpdateForm(PersonId, PersonType).value;
    window.open(url, "_self");
    $.modal.close(); // !important: phải có để đóng bảng dữ liệu.
}


function GetItemCrimeSubject() {
    var allVals = [];
    $('#sl_toidanh :checked').each(function () {
        allVals.push($(this).val());
    });
    var text = allVals;
    return text;
}

function selectLevelType() {
    var ltype = $("#selectlevel").val();
    $("#SelectLocationZone").html(Portal.SODC.IDIS.AddNewCrime.ServerSideRenderLocationSelect(ltype).value);
}


function selectLevelTypeforUpdateCrime() {
    var ltype = $("#selectlevel").val();
    $("#SelectLocationZone").html(Portal.SODC.IDIS.FCrimeEditWP.ServerSideRenderLocationSelect(ltype).value);
}

function selectLevelTypeforInsertCrime() {
    var ltype = $("#selectlevel").val();
    $("#SelectLocationZone").html(Portal.SODC.IDIS.AddNewCrime.ServerSideRenderLocationSelect(ltype).value);
}

function selectLevelTypeForListCase() {
    var ltype = $("#selectlevel").val();
    $("#SelectLocationZone").html(Portal.SODC.IDIS.ListCrimeCase.ServerSideRenderLocationSelect(ltype).value);
}

function selectLevelTypeforUpdateCase() {
    var ltype = $("#selectlevelOfCase").val();
    var LocationIdCase = $("#_locationselCase").val();
    $("#SelectLocationZoneCase").html(Portal.SODC.IDIS.FCrimeEditWP.ServerSideRenderLocationCaseSelect(ltype, LocationIdCase).value);
}

// For upload Image 
function ClientUploadImageUrlFromUpdate(AddictId) {
    var PersonType = false;
    Url = Portal.SODC.IDIS.FCrimeEditWP.GetUpdateImageUrl(AddictId, PersonType).value;
    if (Url.indexOf("ERROR") != -1) {
        alert(Url);
        return;
    }
    retValue = window.open(Url, "_blank");
}

function ClientDeleteImages(PersonId) {
    ConfirmUploadImageMsg = Portal.SODC.IDIS.FCrimeEditWP.GetConfirmDeleteMsg().value;
    if (confirm(ConfirmUploadImageMsg) == false) return;
    Url = Portal.SODC.IDIS.FCrimeEditWP.ServerDeleteImages(PersonId).value;
    if (Url.indexOf("ERROR") != -1) {
        alert(Url);
        return;
    }
    alert(Url);
}

function ClientUploadImageUrlFromInsert(AddictId) {
    var PersonType = false;
    Url = Portal.SODC.IDIS.FCrimeEditWP.GetUpdateImageUrl(PersonType).value;
    if (Url.indexOf("ERROR") != -1) {
        alert(Url);
        return;
    }
    retValue = window.open(Url, "_blank");
}

function selectLevelTypeForListCrime() {
    var ltype = $("#selectlevel").val();
    $("#SelectLocationZone").html(Portal.SODC.IDIS.FCrimeWP.ServerSideRenderLocationSelect(ltype).value);
}


function ClientShowAddnewCrimeForm() {
    Url = Portal.SODC.IDIS.FCrimeWP.GetShowAddNewsForm().value;
    if (Url.indexOf("ERROR") != -1) {
        alert(Url);
        return;
    }
    retValue = window.open(Url, "_blank");
}

function ClientShowViewForm(CaseId) {
    Url = Portal.SODC.IDIS.ListCrimeCase.GetShowViewForm(CaseId).value;
    if (Url.indexOf("ERROR") != -1) {
        alert(Url);
        return;
    }
    retValue = window.open(Url, "_blank");
}


function ViewCaseDetail(CaseId) {
    Url = Portal.SODC.IDIS.FCrimeEditWP.GetShowViewForm(CaseId).value;
    if (Url.indexOf("ERROR") != -1) {
        alert(Url);
        return;
    }
    retValue = window.open(Url, "_blank");
}


function ClientShowEditCrimeForm(PersonId) {
    Url = Portal.SODC.IDIS.FCrimeWP.GetShowUpdateForm(PersonId).value;
    if (Url.indexOf("ERROR") != -1) {
        alert(Url);
        return;
    }
    retValue = window.open(Url, "_blank");
}

function ClientShowDetailCrimeForm(PersonId, Type) {
    Url = Portal.SODC.IDIS.FCrimeWP.GetShowDetailForm(PersonId, Type).value;
    if (Url.indexOf("ERROR") != -1) {
        alert(Url);
        return;
    }
    retValue = window.open(Url, "_blank");
}


function ClientDoSearchByLocation() {

    var Keyword = null;
    var HomeTown = null;
    var LocationId = $("#_locationsel").val();
    var Age = 0;
    result = document.getElementById("ContentSearchResult");
    if (LocationId) {
        result.style.display = "block";
        ps = null;
        Ret = Portal.SODC.IDIS.FCrimeWP.GetResult("app", LocationId, Keyword, HomeTown, Age, 0, "JumpPageSearchResult", ps).value;
        if (Ret.indexOf("Nodata") != -1) {
            result.style.display = "none";
            document.getElementById("divProcessingSearchResult").innerHTML = "Không có dữ liệu!";
        } else {
            result.innerHTML = Ret;
        }
    } else {
        result.innerHTML = "Chưa xác định được địa phương !!!";
    }
}

//For search Case

function ClientDoSimpleSearchCaseByLocation() {
    var Keyword = null;
    var CrimeSubject = null;
    var Sentenced = null;
    var CaseSubject = null;
    var LocationId = $("#_locationsel").val();
    result = document.getElementById("ContentSearchResult");
    document.getElementById("divProcessingSearchResult").innerHTML = Portal.SODC.IDIS.ListCrimeCase.GetProcessingText().value;
    if (result.style)
        if (LocationId) {
            ps = null;
            result.style.display = "block";
            CaseSubject = $("#txt_tieude").val();
            RetValue = Portal.SODC.IDIS.ListCrimeCase.GetResult("app", LocationId, Keyword, CrimeSubject, Sentenced, CaseSubject, 0, "JumpPageSearchResultCase", ps).value;
            if (RetValue.indexOf("Nodata") != -1) {
                result.style.display = "none";
                document.getElementById("divProcessingSearchResult").style.display = "block";
                document.getElementById("divProcessingSearchResult").innerHTML = "Không có dữ liệu!";
            } else {
                if (RetValue.indexOf("ERROR") != -1) {
                    alert(RetValue.replace("ERROR: ", ""));
                    return;
                } else {
                    result.innerHTML = RetValue;
                    document.getElementById("divProcessingSearchResult").style.display = "none";
                }
            }
        } else {
            result.innerHTML = "Chưa xác định được địa phương !!!";
        }
}

//function ClientDoSimpleSearchCase() {
//    document.getElementById("divProcessingSearchResult").innerHTML = "Đang tìm kiếm xin vui lòng đợi...";    
//    setTimeout("RealClientDoSimpleSearchCase()", 10);
//}

function ClientDoSimpleSearchCase(Type) {

    result = document.getElementById("ContentSearchResult");
    document.getElementById("divProcessingSearchResult").innerHTML = Portal.SODC.IDIS.ListCrimeCase.GetProcessingText().value;
    //document.getElementById("divProcessingSearchResult").innerHTML = "";
    result.innerHTML = "";
    var LocationId = $("#_locationsel").val();
    rValue = null;
    ps = null;
    if (Type == '1') {
        var Keyword = null;
        var CrimeSubject = null;
        var CaseSubject = null;
        Keyword = document.getElementById("txtSearchKeyword").value;
        elem = document.getElementById("Notkey");
        CaseSubject = $("#txt_tieude").val();
        RetValue = Portal.SODC.IDIS.ListCrimeCase.GetResult("app", LocationId, Keyword, null, CaseSubject, 0, "JumpPageSearchResultCase", ps, rValue).value;
    } else {
        // get conditon
        var frDate = document.getElementById("drpDaytxtFieldFromCaseDate").options[document.getElementById("drpDaytxtFieldFromCaseDate").selectedIndex].value + '/' + document.getElementById("drpMonthtxtFieldFromCaseDate").options[document.getElementById("drpMonthtxtFieldFromCaseDate").selectedIndex].value + '/' + document.getElementById("drpYeartxtFieldFromCaseDate").options[document.getElementById("drpYeartxtFieldFromCaseDate").selectedIndex].value; ;
        var toDate = document.getElementById("drpDaytxtFieldToCaseDate").options[document.getElementById("drpDaytxtFieldToCaseDate").selectedIndex].value + '/' + document.getElementById("drpMonthtxtFieldToCaseDate").options[document.getElementById("drpMonthtxtFieldToCaseDate").selectedIndex].value + '/' + document.getElementById("drpYeartxtFieldToCaseDate").options[document.getElementById("drpYeartxtFieldToCaseDate").selectedIndex].value;

        if (frDate == "//") {
            frDate = null;
        }
        if (toDate == "//") {
            toDate = null;
        }

        ptVanchuyen = document.getElementById("sl_phuongthuc").options[document.getElementById("sl_phuongthuc").selectedIndex].value;

        rValue = ClientDoSearch();
        RetValue = Portal.SODC.IDIS.ListCrimeCase.GetResult("app", LocationId, ptVanchuyen, frDate, toDate, 0, "JumpPageSearchResultCase", ps, rValue).value;
    }
    if (RetValue.indexOf("ERROR") != -1) {
        document.getElementById("divProcessingSearchResult").innerHTML = "";
        alert(RetValue.replace("ERROR: ", ""));
        result.innerHTML = "";
        return;
    }
    document.getElementById("divProcessingSearchResult").innerHTML = "";
    result.innerHTML = RetValue;
    rValue = null;
}
//For search Adv
function ExecuteSearch() {
    rValue = ClientDoSearch();
}

function ExecuteSearchCase() {
    rValue = ClientDoSearch();
}

function ClientDoSimpleSearchCrime(Type) {
    var ltype = $("#selectlevel").val();
    if (ltype == "0") {
        alert("Chưa xác định địa phương!");
        return;
    }
    var LocationId = $("#_locationsel").val();
    ps = null;
    rValue = null;
    var toidanh = null;
    var result = document.getElementById("ContentSearchResult");
    if (Type == '1') {
        var Keyword = document.getElementById("txtSearchKeyword").value;
        var HomeTown = document.getElementById("txt_hometown").value;
        var Indent = document.getElementById("txt_indent").value;
        var Case = document.getElementById("txt_case").value;
        var Age = document.getElementById("select_age").options[document.getElementById("select_age").selectedIndex].value;
        result.style.display = "block";
        document.getElementById("divProcessingSearchResult").innerHTML = Portal.SODC.IDIS.FCrimeWP.GetProcessingText().value;
        Ret = Portal.SODC.IDIS.FCrimeWP.GetResult("app", LocationId, Keyword, HomeTown, Age, Indent, Case, 0, "JumpPageSearchResult", ps, rValue, toidanh).value;
    } else {
        rValue = ClientDoSearch();
        toidanh = GetItemCrimeSubject();
        document.getElementById("divProcessingSearchResult").innerHTML = Portal.SODC.IDIS.FCrimeWP.GetProcessingText().value;
        Ret = Portal.SODC.IDIS.FCrimeWP.GetResult("app", LocationId, Keyword, HomeTown, Age, Indent, Case, 0, "JumpPageSearchResult", ps, rValue, toidanh).value;
    }
    if (Ret.indexOf("ERROR") != -1) {
        document.getElementById("divProcessingSearchResult").innerHTML = "";
        alert(Ret.replace("ERROR: ", ""));
        result.innerHTML = "";
        return;
    }
    document.getElementById("divProcessingSearchResult").innerHTML = "";
    result.innerHTML = Ret;
}

function JumpPageSearchResult(WebpartId, MaxItems, ItemsPerRow, NoOfVisiblePage, CurrentPage, JumpJavaScript) {
    document.getElementById("divProcessingSearchResult").innerHTML = Portal.SODC.IDIS.FCrimeWP.GetProcessingText().value;
    setTimeout("RealJumpPageSearchResult('','" + MaxItems + "',20, 10, '" + CurrentPage + "', 'RealJumpPageSearchResult')", 10);
}
function RealJumpPageSearchResult(WebpartId, MaxItems, ItemsPerRow, NoOfVisiblePage, CurrentPage, JumpJavaScript) {
    PageIndex = CurrentPage;
    LocationId = document.getElementById("txt_LocationId").value;
    Keyword = document.getElementById("txtSearchKeyword").value;
    HomeTown = document.getElementById("txt_hometown").value;
    var Indent = document.getElementById("txt_indent").value;
    var Case = document.getElementById("txt_case").value;
    Age = getData();
    ps = null;
    rValue = ClientDoSearch();
    retValue = Portal.SODC.IDIS.FCrimeWP.GetResult(WebpartId, LocationId, Keyword, HomeTown, Age, Indent, Case, CurrentPage, JumpJavaScript, ps, rValue).value;
    if (retValue.indexOf("ERROR") != -1) {
        alert(retValue);
        return;
    }
    document.getElementById("divProcessingSearchResult").innerHTML = "";
    document.getElementById("ContentSearchResult").innerHTML = retValue;
}

function JumpPageSearchResultCase(WepartId, MaxItems, ItemsPerRow, NoOfVisiblePage, CurrentPage, JumpJavaScript) {
    document.getElementById("divProcessingSearchResult").innerHTML = Portal.SODC.IDIS.ListCrimeCase.GetProcessingText().value;
    setTimeout("RealJumpPageSearchResultCase('','" + MaxItems + "', 20,10, '" + CurrentPage + "', 'RealJumpPageSearchResultCase')", 10);
}
function RealJumpPageSearchResultCase(WebPartId, MaxItems, ItemsPerRow, NoOfVisiblePage, CurrentPage, JumpJavaScript) {
    PageIndex = CurrentPage;
    LocationId = document.getElementById("txt_LocationId").value;
    Keyword = document.getElementById("txtSearchKeyword").value;
    CrimeSubject = "";
    CaseSubject = document.getElementById("txt_tieude").value;
    Sentenced = null;
    ps = null;
    rValue = ClientDoSearch();
    retValue = Portal.SODC.IDIS.ListCrimeCase.GetResult(WebPartId, LocationId, Keyword, CrimeSubject, CaseSubject, CurrentPage, JumpJavaScript, ps, rValue).value;
    if (retValue.indexOf("ERROR") != -1) {
        alert(retValue.replace("ERROR: ", ""));
        return;
    }
    document.getElementById("divProcessingSearchResult").innerHTML = "";
    document.getElementById("ContentSearchResult").innerHTML = retValue;
}


function getData() {
    myData = document.getElementById("select_age").options[document.getElementById("select_age").selectedIndex].value;
    return myData;
}

// AddNewCrime

function ClientResetAllFieldCrime() {

    var myString = $("#txt_Envidence").val();
    var valueEnvidence = GetValueEnvidenceCase(myString);
    var textBoxes = $("input[type='text']");
    for (var i = 0; i < textBoxes.length; i++) {
        textBoxes[i].value = "";
    }
    document.getElementById("txt_usdConvert").value = "";
    document.getElementById("drcnguyenquan").value = "";
    document.getElementById("drcnoidk").value = "";
    document.getElementById("drcchoohn").value = "";
    $("#drcrbtmale").attr('checked', true);
    $("#drckotongiao").attr('checked', true);
    document.getElementById("drcchecktienanmt").checked = false;
    document.getElementById("drcchecktienan").checked = false;
    document.getElementById("drccheckxuphat").checked = false;
    document.getElementById("drcchecktienankhac").checked = false;
    $("#drcrbtkinh").attr('checked', true);
    $("#drcvietnam").attr('checked', true);
    document.getElementById("drcthanhphan").selectedIndex = 0;
    document.getElementById("drcvieclam").selectedIndex = 0;
    document.getElementById("drcfullname").focus();

    document.getElementById("drpDaydrcbirthdate").selectedIndex = 0;
    document.getElementById("drpMonthdrcbirthdate").selectedIndex = 0;
    document.getElementById("drpYeardrcbirthdate").selectedIndex = 0;

    document.getElementById("drpDaydrcngaycap").selectedIndex = 0;
    document.getElementById("drpMonthdrcngaycap").selectedIndex = 0;
    document.getElementById("drpYeardrcngaycap").selectedIndex = 0;

}


function checkdate(date) {
    /*var validformat = /^\d{2}\/\d{2}\/\d{4}$/;
    var returnval = false;
    if (!validformat.test(date)) {
    alert("Nhập sai định dạng ngày.");
    }
    else {
    var dayfield  = date.split("/")[0];
    var monthfield = date.split("/")[1];
    var yearfield = date.split("/")[2];
    var dayobj = new Date(yearfield, monthfield - 1, dayfield);
    if ((dayobj.getMonth() + 1 != monthfield) || (dayobj.getDate() != dayfield) || (dayobj.getFullYear() != yearfield)) {
    alert("Nhập theo định dạng tháng/ngày/năm.");
    }
    else {
    returnval = true;
    }
    }*/
    // TODO : CheckDate in javascript
    return true;
}



var mavuan, ngayvuan, ngayxetxu, heroin, thuocphien,
 matuyth_g, matuyth_ml, gaynghien_v, gaynghien_l, huongthan_v,
 huongthan_l, tienchat_l, tienchat_kg,
  cansa, vnd, ngoaite, usd, fother, usdConvert, kimkhi, tskhac, vukhi, hungkhi, vuan,
  nguongoc, ptVanchuyen, amphetamine_ml, amphetamine_g, coca_g,
  coca_ml, lsd_g, lsd_ml;

function CheckIdentification(cmt) {
    var IsTrue = true;
    if (cmt.length < 9) {
        alert("Độ dài CMND phải từ 9 số,xin nhập lại!");
        IsTrue = false;
    } else {
        Ret = Portal.SODC.IDIS.AddNewCrime.CheckexitIdentification(cmt).value;
        if (Ret) {
            alert("Số CMND này đã tồn tại trong hệ thống,xin nhập lại!");
            IsTrue = false;
        }
    }
    return IsTrue;
}

function CheckStatus(value) {
    if (value == "4" || value == "5" || value == "0") {
        $('#txt_nam').attr('disabled', 'disabled');
        $('#txt_thang').attr('disabled', 'disabled');
    } else {
        $('#txt_nam').attr('disabled', '');
        $('#txt_thang').attr('disabled', '');
    }
}

function ClientSideCheckValidate() {
    var locationId = $("#_locationsel").val();
    if (typeof (locationId) == 'undefined' || locationId == null) {
        var LocationId_Curent = $("#LocationId_Curent").val();
        locationId = LocationId_Curent;
    }
    if (locationId == "") {
        alert("Chọn địa phương!");
        return;
    }
    //    ngaynhan = document.getElementById("drcngaynhan").value;

    ngaynhan = document.getElementById("drpDaydrcngaynhan").options[document.getElementById("drpDaydrcngaynhan").selectedIndex].value + '/' + document.getElementById("drpMonthdrcngaynhan").options[document.getElementById("drpMonthdrcngaynhan").selectedIndex].value + '/' + document.getElementById("drpYeardrcngaynhan").options[document.getElementById("drpYeardrcngaynhan").selectedIndex].value;

    if (ngaynhan == "//") {
        alert("Chưa nhập ngày nhận!");
        document.getElementById("drpDaydrcngaynhan").focus();
        return;
    }
    checkngaynhan = checkdate(ngaynhan);
    if (checkngaynhan == false) {
        document.getElementById("drpDaydrcngaynhan").focus();
        document.getElementById("drpDaydrcngaynhan").select();
        return;
    }
    fullname = document.getElementById("drcfullname").value;
    if (fullname == "") {
        alert("Nhập họ tên đầy đủ!");
        document.getElementById("drcfullname").focus();
        return;
    }
    checksex = $('input[name=rbtchecksex]:checked').val();
    //    birthdate = document.getElementById("drcbirthdate").value;

    birthdate = document.getElementById("drpDaydrcbirthdate").options[document.getElementById("drpDaydrcbirthdate").selectedIndex].value + '/' + document.getElementById("drpMonthdrcbirthdate").options[document.getElementById("drpMonthdrcbirthdate").selectedIndex].value + '/' + document.getElementById("drpYeardrcbirthdate").options[document.getElementById("drpYeardrcbirthdate").selectedIndex].value;
    if (birthdate == "//") {
        alert("Nhập ngày sinh!");
        document.getElementById("drpDaydrcbirthdate").focus();
        return;
    }
    checkbirthdate = checkdate(birthdate);
    if (checkbirthdate == false) {
        document.getElementById("drpDaydrcbirthdate").select();
        return;
    }
    cmt = document.getElementById("drcCMT").value;
    if (cmt != "") {
        // Check CMT
        if (!CheckIdentification(cmt)) {
            document.getElementById("drcCMT").focus();
            return;
        }
        //        ngaycap = document.getElementById("drcngaycap").value;
        ngaycap = document.getElementById("drpDaydrcngaycap").options[document.getElementById("drpDaydrcngaycap").selectedIndex].value + '/' + document.getElementById("drpMonthdrcngaycap").options[document.getElementById("drpMonthdrcngaycap").selectedIndex].value + '/' + document.getElementById("drpYeardrcngaycap").options[document.getElementById("drpYeardrcngaycap").selectedIndex].value;
        if (ngaycap == "//") {
            alert("Nhập ngày cấp CMND!");
            document.getElementById("drpDaydrcngaycap").focus();
            return;
        }
        checkngaycap = checkdate(ngaycap);
        if (checkngaycap == false) {
            document.getElementById("drpDaydrcngaycap").focus();
            return;
        }
        noicap = document.getElementById("drcnoicap").value;
        if (noicap == "") {
            alert("Nhập nơi cấp CMND!");
            document.getElementById("drcnoicap").focus();
            return;
        }
    } else {
        ngaycap = "";
        noicap = "";
    }
    trinhdovh = document.getElementById("drctdvh").value;
    if (trinhdovh == "0") {
        alert("Chọn trình độ văn hóa!");
        return;
    }
    nguyenquan = document.getElementById("drcnguyenquan").value;
    if (nguyenquan == "") {
        alert("Nhập nguyên quán!");
        document.getElementById("drcnguyenquan").focus();
        return;
    }
    choohn = document.getElementById("drcchoohn").value;
    if (choohn == "") {
        alert("Nhập chỗ ở hiện nay!");
        document.getElementById("drcchoohn").focus();
        return;
    }
    tendaithe = document.getElementById("drctendaithe").value;
    noidk = document.getElementById("drcnoidk").value;
    if (noidk == "") {
        alert("Nhập hộ khẩu thường trú!");
        document.getElementById("drcnoidk").focus();
        return;
    }
    tongiao = $('input[name=drctongiao]:checked').val();
    condangvien = document.getElementById("drcchecktienanmt").checked;
    tienan = document.getElementById("drcchecktienan").checked;
    xuphat = document.getElementById("drccheckxuphat").checked;
    tienankhac = document.getElementById("drcchecktienankhac").checked;

    //right col
    checkdantoc = $('input[name=drcdantoc]:checked').val();
    checkquoctich = $('input[name=drcquoctich]:checked').val();
    vieclam = document.getElementById("drcvieclam").options[document.getElementById("drcvieclam").selectedIndex].value;
    if (vieclam == "0") {
        alert("Chọn tình hình việc làm!");
        return;
    }
    thanhphan = document.getElementById("drcthanhphan").options[document.getElementById("drcthanhphan").selectedIndex].value;
    if (thanhphan == "0") {
        alert("Chọn thành phần của đối tượng!");
        return;
    }

    CaseCode = document.getElementById("txt_mavuan").value;
    CaseId = document.getElementById("txt_caseid").value;

    executedStatus = $('input[name=rbtchecExecutedStatus]:checked').val();
    toidanh = GetItemCrimeSubject();
    var ngaythihanh = document.getElementById("drpDaytxt_ngayxetxu").options[document.getElementById("drpDaytxt_ngayxetxu").selectedIndex].value + '/' + document.getElementById("drpMonthtxt_ngayxetxu").options[document.getElementById("drpMonthtxt_ngayxetxu").selectedIndex].value + '/' + document.getElementById("drpYeartxt_ngayxetxu").options[document.getElementById("drpYeartxt_ngayxetxu").selectedIndex].value;
    var PersonId = $("#txt_matoipham").val();
    document.getElementById("divProcessing").innerHTML = Portal.SODC.IDIS.AddNewCrime.GetProcessing().value;
    if (CaseCode != "") {
        if (Portal.SODC.IDIS.AddNewCrime.CheckexitCaseCode(CaseCode).value == true) {
            /* Insert Crime ,CaseStatus  :*/
            retVal = Portal.SODC.IDIS.AddNewCrime.ServerSideAddNewCrime(ngaynhan, fullname, checksex, birthdate, cmt, ngaycap, noicap, nguyenquan,
																choohn, tendaithe, noidk, tongiao, condangvien, tienan, xuphat, tienankhac, checkdantoc,
																checkquoctich, CaseId, thanhphan, vieclam, toidanh,
																ngaythihanh, locationId, PersonId, trinhdovh, executedStatus).value;
            if (retVal.indexOf("ERROR") != -1) {
                alert(retVal.replace("ERROR: ", ""));
                return;
                document.getElementById("divProcessing").innerHTML = "";
            } else {
                ResetAllFieldCase();
                ClientResetAllFieldCrime();
                document.getElementById("divProcessing").innerHTML = "";
                UploadImage(retVal);
            }
        } else {
            // Get info Case
            GetCaseInfo();
            // Get value Envidence for Case
            var myString = $("#txt_Envidence").val();
            var valueEnvidence = GetValueEnvidenceCase(myString);
            /* Insert Crime ,Case and CaseStatus:*/
            retVal = Portal.SODC.IDIS.AddNewCrime.ServerSideAddNewCrimeCaseStatus(
                                    ngaynhan, fullname, checksex, birthdate, cmt, ngaycap, noicap, nguyenquan,
					                choohn, tendaithe, noidk, tongiao, condangvien, tienan, xuphat, tienankhac, checkdantoc,
					                checkquoctich, CaseCode, thanhphan, vieclam, toidanh,
					                ngaythihanh, vuan, ngayvuan, nguongoc, ptVanchuyen, locationId,
                                    PersonId, valueEnvidence, trinhdovh, executedStatus, usdConvert).value;

            if (retVal.indexOf("ERROR") != -1) {
                alert(retVal.replace("ERROR: ", ""));
                document.getElementById("divProcessing").innerHTML = "";
                return;
            } else {
                ResetAllFieldCase();
                ClientResetAllFieldCrime();
                document.getElementById("divProcessing").innerHTML = "";
                UploadImage(retVal);
            }
        }
    } else {
        document.getElementById("divProcessing").innerHTML = "";
        alert("Yêu cầu nhập thông tin vụ án cho đối tượng!");
    }
}

// Lấy thông tin vụ án
function GetCaseInfo() {
    mavuan = document.getElementById("txt_mavuan").value;
    if (mavuan == "") {
        alert("Nhập mã vụ án!!!");
        document.getElementById("txt_mavuan").select();
        return false;
    }

    //ngayvuan = $("#txt_ngayvuan").val();
    ngayvuan = document.getElementById("drpDaytxt_ngayvuan").options[document.getElementById("drpDaytxt_ngayvuan").selectedIndex].value + '/' + document.getElementById("drpMonthtxt_ngayvuan").options[document.getElementById("drpMonthtxt_ngayvuan").selectedIndex].value + '/' + document.getElementById("drpYeartxt_ngayvuan").options[document.getElementById("drpYeartxt_ngayvuan").selectedIndex].value;

    if (ngayvuan == "") {
        alert("Chưa nhập ngày thành lập vụ án!");
        document.getElementById("drpDaytxt_ngayvuan").select();
        return false;
    }

    //ngayxetxu = $("#txt_ngayxetxu").val();

    ngayxetxu = document.getElementById("drpDaytxt_ngayxetxu").options[document.getElementById("drpDaytxt_ngayxetxu").selectedIndex].value + '/' + document.getElementById("drpMonthtxt_ngayxetxu").options[document.getElementById("drpMonthtxt_ngayxetxu").selectedIndex].value + '/' + document.getElementById("drpYeartxt_ngayxetxu").options[document.getElementById("drpYeartxt_ngayxetxu").selectedIndex].value;

    //    if (checkdate(ngayxetxu) == false) {
    //        alert("Chưa nhập ngày xét xử");
    //        document.getElementById("txt_ngayxetxu").select();
    //        return false;
    //    }

    //GetValueEnvidenceCase(myString);
    nguongoc = $("#txt_OriginDrugSeized").val();
    if (nguongoc == "") {
        alert("Nhập nguồn gốc ma túy!!!");
        document.getElementById("txt_OriginDrugSeized").select();
        return false;
    }
    ptVanchuyen = document.getElementById("sl_phuongthuc").options[document.getElementById("sl_phuongthuc").selectedIndex].value;
    if (ptVanchuyen == "0") {
        alert("Chọn phương thức vận chuyển!!!");
        document.getElementById("sl_phuongthuc").select();
        return false;
    }
    usdConvert = $("#txt_usdConvert").val();
    toidanh = GetItemCrimeSubject();
    vuan = $("#txt_tieude").val();
    if (vuan == "") {
        alert("Nhập tiêu vụ án!!!");
        document.getElementById("txt_tieude").focus();
        return false;
    }
}

function GetValueEnvidenceCase(myString) {
    var mySplitResult = myString.split("|");
    var myId = '';
    var getVal = '';
    var value = '';
    var Unit = '';
    for (i = 0; i < mySplitResult.length; i++) {
        myId = mySplitResult[i].split(",");
        value = document.getElementById(myId[0]).value;
        if (value != null && value != "") {
        //    if (IsNumeric(value)) {
                getVal += mySplitResult[i] + '|' + value + ";";
//            } else {
//                alert("Yêu cầu nhập số!");
//                document.getElementById(myId[0]).focus();
//                return false;
//            }
        }
    }
    return getVal;
}

function UploadImage(PersonId) {
    Msg = Portal.SODC.IDIS.AddNewCrime.GetConfirmUploadImage().value;
    if (confirm(Msg) == false) return;
    /***/
    var PersonType = false;
    Url = Portal.SODC.IDIS.AddNewCrime.GetUpdateImageUrl(PersonId, PersonType).value;
    if (Url.indexOf("ERROR") != -1) {
        alert(Url);
        return;
    }
    retValue = window.open(Url, "_blank");
}


function ResetAllFieldCase() {
    var textBoxes = $("input[type='text']");
    for (var i = 0; i < textBoxes.length; i++) {
        textBoxes[i].value = "0";
    }
    document.getElementById("txt_mavuan").value = '';

    //document.getElementById("txt_ngayvuan").value = '';
    document.getElementById("drpDaytxt_ngayvuan").selectedIndex = 0;
    document.getElementById("drpMonthtxt_ngayvuan").selectedIndex = 0;
    document.getElementById("drpYeartxt_ngayvuan").selectedIndex = 0;


    document.getElementById("txt_tieude").value = '';
    //document.getElementById("txt_ngayxetxu").value = '';
    document.getElementById("drpDaytxt_ngayxetxu").selectedIndex = 0;
    document.getElementById("drpMonthtxt_ngayxetxu").selectedIndex = 0;
    document.getElementById("drpYeartxt_ngayxetxu").selectedIndex = 0;

}

function SearchCaseById() {
    var Keyword = null;
    em = document.getElementById("ClientRenderCaseInfomationZone");
    Keyword = document.getElementById("txt_mavuan").value;
    if (Keyword != "") {
        checkCase = Portal.SODC.IDIS.AddNewCrime.CheckexitCase(Keyword).value;
        if (checkCase == false) {
            alert("Vụ án này không tồn tại hoặc đã bị xóa,xin kiểm tra lại!");
        } else {
            em.innerHTML = "";
            retValue = Portal.SODC.IDIS.AddNewCrime.ClientRenderCaseInfomationZone(Keyword).value;
            if (retValue.indexOf("ERROR") != -1) {
                alert(retValue);
            } else {
                em.innerHTML = retValue;
            }
        }
    }
    else {
        alert("Nhập mã vụ án!")
    }
}

function SearchCaseById1() {
    var Keyword = null;
    em = document.getElementById("ClientRenderCaseInfomationZone");
    Keyword = document.getElementById("txt_caseid").value;
    if (Keyword != "") {
        checkCase = Portal.SODC.IDIS.FCrimeEditWP.CheckexitCase(Keyword).value;
        if (checkCase == false) {
            alert("Vụ án này không tồn tại hoặc đã bị xóa,xin kiểm tra lại!");
        } else {
            em.innerHTML = "";
            retValue = Portal.SODC.IDIS.FCrimeEditWP.ClientRenderCaseInfomationZone(Keyword).value;
            if (retValue.indexOf("ERROR") != -1) {
                alert(retValue);
            } else {
                em.innerHTML = retValue;
            }
        }
    }
    else {
        alert("Nhập mã vụ án!")
    }
}


function SearchCaseByIdForUpdate(CaseId, PersonId) {
    document.getElementById("divProcessing1").innerHTML = Portal.SODC.IDIS.FCrimeEditWP.GetProcessing().value;
    //ShowFormInputCase();
    em = document.getElementById("ContentAddCase");
    if (em.style.display == "none")
        em.style.display = "block";
    em = document.getElementById("ClientRenderCaseInfomationZone");
    retValue = Portal.SODC.IDIS.FCrimeEditWP.ClientRenderCaseInfomationZone(CaseId, PersonId).value;
    if (retValue.indexOf("ERROR") != -1) {
        alert(retValue);
    } else {
        em.innerHTML = retValue;
    }
    document.getElementById("divProcessing1").innerHTML = "";
}

function ShowFormInputCase() {
    em = document.getElementById("ContentAddCase");
    if (em.style.display == "block")
        em.style.display = "none";
    else {
        em.style.display = "block";
    }
}


function ShowFormInputCaseInEditCrime(PersonId, CaseId) {
    //    em = document.getElementById("ContentAddCase");
    //    if (em.style.display == "block") {
    //        em.style.display = "none";        
    //    }
    //    else {
    //        em.style.display = "block";        
    //    }
    SearchCaseByIdForUpdate(CaseId, PersonId);
}



function ShowAdvSearchCase() {
    em1 = document.getElementById("divSimpleSearchCase");
    em = document.getElementById("advSearchCase");
    if (em.style.display == "block") {
        em.style.display = "none";
        em1.style.display = "block";
    }
    else {
        em.style.display = "block";
        em1.style.display = "none";
    }
}

function CloseFormInputCase() {
    var em;
    em = document.getElementById("insnewcasepanel");
    em.style.display = 'none';
}


function ClientSideCheckUpdateCrime(CrimeId, CaseId) {
    /* Get info Crime for Update */
    //    ngaynhan = document.getElementById("drcngaynhan").value;
    ngaynhan = document.getElementById("drpDaydrcngaynhan").options[document.getElementById("drpDaydrcngaynhan").selectedIndex].value + '/' + document.getElementById("drpMonthdrcngaynhan").options[document.getElementById("drpMonthdrcngaynhan").selectedIndex].value + '/' + document.getElementById("drpYeardrcngaynhan").options[document.getElementById("drpYeardrcngaynhan").selectedIndex].value;
    if (ngaynhan == "//") {
        alert("Chưa nhập ngày nhận!");
        document.getElementById("drcngaynhan").focus();
        return;
    }
    checkngaynhan = checkdate(ngaynhan);
    if (checkngaynhan == false) {
        document.getElementById("drpDaydrcngaynhan").focus();
        document.getElementById("drpDaydrcngaynhan").select();
        return;
    }
    fullname = document.getElementById("drcfullname").value;
    if (fullname == "") {
        alert("Chưa nhập họ tên tội phạm!");
        document.getElementById("drcfullname").focus();
        return;
    }
    checksex = $('input[name=rbtchecksex]:checked').val();

    //    birthdate = document.getElementById("drcbirthdate").value;
    birthdate = document.getElementById("drpDaydrcbirthdate").options[document.getElementById("drpDaydrcbirthdate").selectedIndex].value + '/' + document.getElementById("drpMonthdrcbirthdate").options[document.getElementById("drpMonthdrcbirthdate").selectedIndex].value + '/' + document.getElementById("drpYeardrcbirthdate").options[document.getElementById("drpYeardrcbirthdate").selectedIndex].value;
    if (birthdate == "//") {
        alert("Nhập ngày sinh của đối tượng!");
        document.getElementById("drpDaydrcbirthdate").focus();
        return;
    }
    checkbirthdate = checkdate(birthdate);
    if (checkbirthdate == false) {

        document.getElementById("drpDaydrcbirthdate").select();
        return;
    }
    cmt = document.getElementById("drcCMT").value;
    if (cmt != "") {
        //ngaycap = document.getElementById("drcngaycap").value;
        ngaycap = document.getElementById("drpDaydrcngaycap").options[document.getElementById("drpDaydrcngaycap").selectedIndex].value + '/' + document.getElementById("drpMonthdrcngaycap").options[document.getElementById("drpMonthdrcngaycap").selectedIndex].value + '/' + document.getElementById("drpYeardrcngaycap").options[document.getElementById("drpYeardrcngaycap").selectedIndex].value;
        if (ngaycap == "//") {
            alert("Nhập ngày cấp CMND!");
            document.getElementById("drpDaydrcngaycap").focus();
            return;
        }
        checkngaycap = checkdate(ngaycap);
        if (checkngaycap == false) {
            document.getElementById("drpDaydrcngaycap").focus();
            return;
        }
        noicap = document.getElementById("drcnoicap").value;
        if (noicap == "") {
            alert("Nhập nơi cấp!");
            document.getElementById("drcnoicap").focus();
            return;
        }
    }
    else {
        ngaycap = "";
        noicap = "";
    }
    nguyenquan = document.getElementById("drcnguyenquan").value;
    if (nguyenquan == "") {
        alert("Chưa nhập nguyên quán tội phạm!");
        document.getElementById("drcnguyenquan").focus();
        return;
    }
    noidk = document.getElementById("drcnoidk").value;
    if (noidk == "") {
        alert("Chưa nhập nơi đăng ký hộ khẩu thường trú của tội phạm!");
        document.getElementById("drcnoidk").focus();
        return;
    }
    choohn = document.getElementById("drcchoohn").value;
    trinhdovh = document.getElementById("drctdvh").value;
    tendaithe = document.getElementById("drctendaithe").value;
    tongiao = $('input[name=drcdantoc]:checked').val();
    condangvien = document.getElementById("drcchecktienanmt").checked;
    tienan = document.getElementById("drcchecktienan").checked;
    xdrchat = document.getElementById("drccheckxuphat").checked;
    tienankhac = document.getElementById("drcchecktienankhac").checked;
    //right col
    checkdantoc = $('input[name=drcdantoc]:checked').val();
    checkquoctich = $('input[name=drcquoctich]:checked').val();
    var LocationId = $("#_locationsel").val();
    if (typeof (LocationId) == 'undefined' || LocationId == null) {
        var LocationId_Curent = $("#LocationId_Curent").val();
        LocationId = LocationId_Curent;
    }
    vieclam = document.getElementById("drcvieclam").options[document.getElementById("drcvieclam").selectedIndex].value;
    if (vieclam == "0") {
        alert("Chọn tình hình việc làm!");
        return;
    }
    thanhphan = document.getElementById("drcthanhphan").options[document.getElementById("drcthanhphan").selectedIndex].value;
    if (thanhphan == "0") {
        alert("Chọn thành phần của đối tượng!");
        return;
    }
    /* End */
    document.getElementById("divProcessing").innerHTML = Portal.SODC.IDIS.FCrimeEditWP.GetProcessing().value;
    retVal = Portal.SODC.IDIS.FCrimeEditWP.ServerSideUpdateCrime(CrimeId, fullname, checksex, birthdate, cmt,
                                                                 ngaycap, noicap, nguyenquan, choohn, tendaithe,
                                                                 noidk, tongiao, condangvien, tienan, xdrchat, tienankhac,
                                                                 checkdantoc, checkquoctich,
                                                                 ngaynhan, LocationId, CaseId, trinhdovh,
                                                                 vieclam, thanhphan).value;
    if (retVal.indexOf("ERROR") != -1) {
        alert(retVal.replace("ERROR: ", ""));
        return;
        document.getElementById("divProcessing").innerHTML = "";
    }
    document.getElementById("divProcessing").innerHTML = "";
    Msg = Portal.SODC.IDIS.FCrimeEditWP.GetConfirmExitMsg().value;
    if (confirm(Msg) == false) {
        return;
    } else {
        window.close();
    }
}

// For delete CrimePersonStatus
function DeleteCrimeStatus(CaseId, CrimeId, DateRecorded, LocationCode) {
    Msg = Portal.SODC.IDIS.FCrimeEditWP.GetConfirmDeleteMsg().value;
    if (confirm(Msg) == false) return;
    retVal = Portal.SODC.IDIS.FCrimeEditWP.ClientDeleteCrimeCaseStatus(CaseId, CrimeId, DateRecorded, LocationCode).value;
    if (retVal.indexOf("ERROR") != -1) {
        alert(retVal);
        return;
    }
    alert(retVal);
}


function ClientSideUpdateCase(InsertType) {
    GetCaseInfo();
    //    ngaynhan = document.getElementById("drcngaynhan").value;
    ngaynhan = document.getElementById("drpDaydrcngaynhan").options[document.getElementById("drpDaydrcngaynhan").selectedIndex].value + '/' + document.getElementById("drpMonthdrcngaynhan").options[document.getElementById("drpMonthdrcngaynhan").selectedIndex].value + '/' + document.getElementById("drpYeardrcngaynhan").options[document.getElementById("drpYeardrcngaynhan").selectedIndex].value;
    if (ngaynhan == "//") {
        alert("Chưa nhập ngày nhận!");
        document.getElementById("drpDaydrcngaynhan").focus();
        return;
    }
    checkngaynhan = checkdate(ngaynhan);
    if (checkngaynhan == false) {
        document.getElementById("drpDaydrcngaynhan").focus();
        document.getElementById("drpDaydrcngaynhan").select();
        return;
    }
    toidanh = GetItemCrimeSubject();
    thanhphan = document.getElementById("drcthanhphan").options[document.getElementById("drcthanhphan").selectedIndex].value;
    vieclam = document.getElementById("drcvieclam").options[document.getElementById("drcvieclam").selectedIndex].value;
    var LocationId = $("#_locationsel").val();
    var LocationIdCase = $("#_locationselCase").val();
    if (typeof (LocationId) == 'undefined' || LocationId == null) {
        var LocationId_Curent = $("#LocationId_Curent").val();
        LocationId = LocationId_Curent;
    }
    if (typeof (LocationIdCase) == 'undefined' || LocationIdCase == null || LocationIdCase == "") {
        var LocationId_CurentCase = $("#LocationId_CurentOfCase").val();
        LocationIdCase = LocationId_CurentCase;
    }
    var executedStatus = $('input[name=rbtchecExecutedStatus]:checked').val();
    var myString = $("#txt_Envidence").val();
    var valueEnvidence = GetValueEnvidenceCase(myString);
    var CaseId = $("#txt_caseid").val();
    var CrimeId = $("#txt_matoipham").val();
    var CaseCode = $("#txt_mavuan").val();

    if (InsertType == 2) {

        document.getElementById("divProcessing1").innerHTML = Portal.SODC.IDIS.FCrimeEditWP.GetProcessing().value;
        retValue = Portal.SODC.IDIS.FCrimeEditWP.ServerSideUpdateCase(CaseId, CaseCode, vuan, ngayvuan, CrimeId, toidanh,
                                                                     ngayxetxu, LocationIdCase,
                                                                     ngaynhan, nguongoc, ptVanchuyen, valueEnvidence, executedStatus, usdConvert).value;
    } else if (InsertType == 1) {
        //CaseCode = mavuan;
        document.getElementById("divProcessing1").innerHTML = Portal.SODC.IDIS.FCrimeEditWP.GetProcessing().value;
        // check exits case
        //if (Portal.SODC.IDIS.FCrimeEditWP.CheckExitCaseCode(CaseCode).value == true) {
        // if exits :
        // insert new status for crime
        CaseId = $("#txt_caseidhid").val();
        retValue = Portal.SODC.IDIS.FCrimeEditWP.ServerSideAddNewCrimeStatus(CaseId, thanhphan, vieclam,
                                                        toidanh, CrimeId, executedStatus, ngayxetxu, LocationId, ngaynhan).value;
    } else {
        //} else {
        // else:insert new case for crime          
        retValue = Portal.SODC.IDIS.FCrimeEditWP.ServerSideInsertCase(
                                                    CaseCode,
                                                    vuan,
                                                    ngayvuan,
                                                    nguongoc,
                                                    ptVanchuyen,
                                                    CrimeId,
                                                    toidanh,
                                                    ngayxetxu,
                                                    vieclam,
                                                    thanhphan,
                                                    LocationId,
                                                    ngaynhan,
                                                    valueEnvidence,
                                                    LocationIdCase,
                                                    executedStatus,
                                                    usdConvert).value;
        //}
    }


    if (retValue.indexOf("ERROR") != -1) {
        alert(retValue.replace("ERROR: ", ""));
        document.getElementById("divProcessing1").innerHTML = "";
        return;
    }
    alert(retValue);
    document.getElementById("divProcessing1").innerHTML = "";
    ShowFormInputCase();
}

function GetProcessingText() {
    return Portal.SODC.IDIS.CrimeEditWP.GetProcessing().value;
}

//Search case for update  Case
function UsingQuickSearchCase(WebpartId) {
    CaseId = document.getElementById("txt_mavuan").value; // Custom: lấy dữ liệu về số mã vụ án.
    if (CaseId != "") {
        QuickFindCase(CaseId, WebpartId); // Hàm để hiển thị ra bảng dữ liệu về tội phạm
    }
    else {
        alert("Chưa xác định được từ khóa");
        if (WebpartId == 0) {
            retValue = Portal.SODC.IDIS.AddNewCrime.ClientRenderCaseInfomationZone(CaseId).value;
        } else {
            retValue = Portal.SODC.IDIS.FCrimeEditWP.ClientRenderCaseInfomationZone(CaseId, null).value;
        }
        em.innerHTML = retValue;
    }
}

function FoundCase(CaseId, WebpartId) {
    if (CaseId == "") {
        checkCase = false;
    } else {
        checkCase = true;
    }
    if (checkCase == false) {
        alert("Vụ án này không tồn tại hoặc đã bị xóa,xin kiểm tra lại!!!");
        if (WebpartId == "0") {
            retValue = Portal.SODC.IDIS.AddNewCrime.ClientRenderCaseInfomationZone(CaseId).value;
        } else {
            personid = "";
            retValue = Portal.SODC.IDIS.FCrimeEditWP.ClientRenderCaseInfomationZone(CaseId, personid).value;
        }
        em.innerHTML = retValue;
    } else {
        em.innerHTML = "";
        checkCase = Portal.SODC.IDIS.Ultility.CheckexitCaseId(CaseId).value;
        if (checkCase == false) {
            CaseId = "";
        }
        if (WebpartId == "0") {
            retValue = Portal.SODC.IDIS.AddNewCrime.ClientRenderCaseInfomationZone(CaseId).value;
        } else {
            personid = "";
            retValue = Portal.SODC.IDIS.FCrimeEditWP.ClientRenderCaseInfomationZone(CaseId, personid).value;
        }
        em.innerHTML = retValue;
    }
    $.modal.close();
}
// Delete CrimePerson

function DeleteCrimePerson(CrimeId, DateRecorded, LocationId) {
    Msg = Portal.SODC.IDIS.FCrimeWP.GetConfirmDeleteMsg().value;
    if (confirm(Msg) == false) return;
    retVal = Portal.SODC.IDIS.FCrimeWP.ServerSideDeleteCrimePerson(CrimeId, DateRecorded, LocationId).value;
    if (retVal.indexOf("ERROR") != -1) {
        alert(retVal.replace("ERROR: ", ""));
        return;
    }
    alert(retVal);
    ClientDoSimpleSearchCrime(1);
}

function Change_name() {
    var fullname = $("#drcfullname").val();
    if (fullname != "") {
        document.getElementById("drcfullname").value = Portal.SODC.IDIS.Dictionarys.ReformatNamedVie(fullname).value;
    }
}

function ShowValue(Id) {
    var value = document.getElementById(Id).value
    if (value != "") {
        if (!IsNumeric(value)) {
            alert("Yêu cầu nhập số!");
            document.getElementById("lb_" + Id).innerHTML = "";
            return;
        } else {
            document.getElementById("lb_" + Id).innerHTML = Portal.SODC.IDIS.Dictionarys.ReformatNumberVie(value).value;
        }
    } else {
        alert("Bạn phải nhập giá trị để xem tra dữ liệu!");
        return;
    }
}

function IsNumeric(sText) {
    var ValidChars = "0123456789,";
    var IsNumber = true;
    var Char;
    for (i = 0; i < sText.length && IsNumber == true; i++) {
        Char = sText.charAt(i);
        if (ValidChars.indexOf(Char) == -1) {
            IsNumber = false;
        }
    }
    return IsNumber;
}


